package com.dxt.utils;

import com.alibaba.druid.pool.DruidDataSourceFactory;
import org.junit.jupiter.api.Test;

import javax.sql.DataSource;
import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;

/**
 * BelongProject: deliveryManage
 * BelongPackage: com.dxt.utils
 * Description:
 *
 * @Author 段鑫涛
 * @Create 2025/3/30 21:36
 * @Version 1.0
 */
public class JDBCUtil {
    private static DataSource dataSource;

    static {
        // 创建 Properties 对象
        Properties properties = new Properties();
        try {
            // 加载 druid.properties 配置文件
            properties.load(JDBCUtil.class.getResourceAsStream("/druid.properties"));
            // 根据配置文件创建 Druid 数据源
            dataSource = DruidDataSourceFactory.createDataSource(properties);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    //获取dataSource对象
    public static DataSource getDataSource() {
        return dataSource;
    }

    @Test
    public void test() throws SQLException {
        Connection connection = getDataSource().getConnection();
        System.out.println(connection);
    }
}
